﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//////using System.Xml.Linq;
using System.Data;
using KPIS.Utils;
using KPIS.DBM;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.MODEL;
using Telerik.Web.UI;


namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class WF_WelfareData : System.Web.UI.UserControl
    {
        private object _dataItem = null;


        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }
        


        protected bool IsUserControlPostBack
        {
            get
            {
                return this.ViewState["IsUserControlPostBack"] != null;
            }
        }
        //Initializing the new variable updating ViewState data.
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);


            if (!IsUserControlPostBack)
            {
             
                this.ViewState.Add("IsUserControlPostBack", true);
            }

            if (DataItem != null)
            {
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    
                    lblWefSeq.Text = DataBinder.Eval(DataItem, "wef_seq").ToString();
                    lblExtSeq.Text = DataBinder.Eval(DataItem, "ext_seq").ToString();
                    txtName.Text = DataBinder.Eval(DataItem, "wef_name").ToString();
                    txtRemarks.Text  = DataBinder.Eval(DataItem, "remarks").ToString();
                    rdoType.SelectedValue = DataBinder.Eval(DataItem, "ext_flag").ToString();
                    txtExtName.Text = DataBinder.Eval(DataItem, "ext_name").ToString();
              
                    this.btnAddnew.Visible = false;
                    this.btnUpdate.Visible = true;
                }
                else
                {
               
                    this.btnUpdate.Visible = false;
                    this.btnAddnew.Visible = true;
                }
            }
        }



        protected void Page_Load(object sender, EventArgs e)
        {

        }

 
        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            try
            {
                WelfareDataBLL obj = new WelfareDataBLL();
                string wef_name, remarks;
                int ext_seq;

                wef_name = txtName.Text;
                remarks = txtRemarks.Text;
                ext_seq = int.Parse(lblExtSeq.Text  );

                if (obj.chkDupWelfare(wef_name) == true)
                {
                    return;
                }


                obj.insert(wef_name, remarks,ext_seq, 1);


            }
            catch(Exception ex)
            {

            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                WelfareDataBLL obj = new WelfareDataBLL();

                string wef_name, remarks;
                int wef_seq,ext_seq;

                wef_seq = int.Parse(lblWefSeq.Text);  
                ext_seq = int.Parse(lblExtSeq.Text);

                wef_name = txtName.Text;
                remarks = txtRemarks.Text;

                if (obj.chkDupWelfareEdit(wef_name, wef_seq) == true)
                {
                    return;
                }

                obj.Update(wef_seq,wef_name, remarks,ext_seq , 1);   
            }
            catch (Exception ex)
            {

            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }    

     

        protected void btnFindExt_Load(object sender, EventArgs e)
        {

            btnFindExt.Attributes.Add("OnClick", "LinkMDdetail(" + HideExt.ClientID + "," + "'Forms/DialogWF_Ext.aspx?ext_flag=I','../frmIframe.html',700,500)");

        }

        protected void btnFindExt_Click(object sender, ImageClickEventArgs e)
        {




        }

        protected void rdoType_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtExtName.Text = "";
            string ext_flag;
            ext_flag = rdoType.SelectedValue;

            btnFindExt.Attributes.Add("OnClick", "LinkMDdetail(" + HideExt.ClientID + "," + "'Forms/DialogWF_Ext.aspx?ext_flag=" + ext_flag + "','../frmIframe.html',700,500)");

        }

        protected void btnFindExt_Click1(object sender, ImageClickEventArgs e)
        {

            
            string st = HideExt.Value;
            if (st == "")
                return;


            lblExtSeq.Text = st;
            WelfareDataBLL obj = new WelfareDataBLL();
            DataTable dt;
            dt = obj.SelectExtByID(int.Parse(st));

            txtExtName.Text = dt.Rows[0]["ext_name"].ToString();  

         

        }

    }
}